package com.ruicar.afs.cloud.afscase.common.utils;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.ruicar.afs.cloud.components.datadicsync.dto.DicDataDto;
import lombok.experimental.UtilityClass;

import java.util.List;
import java.util.Map;

/**
 * @Description 字典
 * @Author Peng_Jinbo
 * @Date 2020/06/08 10:50
 */
@UtilityClass
public class DicUtils {

    /**
     * @Description key -> title 翻译
     * @Author Peng_Jinbo
     * @Date 2020/6/18 10:56
     */
    public String translate(String dataKey, Map<String, List<DicDataDto>> dicMap) {
        String translatedTitle = "";
        for (Map.Entry<String, List<DicDataDto>> entry : dicMap.entrySet()) {
            if (CollectionUtil.isNotEmpty(entry.getValue())) {
                for (DicDataDto dicDataDto : entry.getValue()) {
                    if (dicDataDto.getValue().equals(dataKey)) {
                        translatedTitle = dicDataDto.getTitle();
                        break;
                    }
                }
            }
            if (StrUtil.isNotBlank(translatedTitle)) {
                break;
            }
        }
        return translatedTitle;
    }

}
